// jquery.jsonp 2.3.1 (c)2012 Julian Aubourg | MIT License
// https://github.com/jaubourg/jquery-jsonp
(function(a) {
    a.jsonp = function(l) {
    	l.needMsg = l.needMsg == null ? true :false;
    	if(l.loadMsg)
    	l.complete = function(r, success) {
        	if(!l.isNotNeedSysPoint) {
	    		if('success' != success) {
    				if(l.needMsg){//是否需要进行提示
    					$MsgBox.alert('未连接到服务器，请检查网络');
    				}
	    		}
	    	}
    	};
    	var success_me = l.success;
		var div = l.error_show;
    	if(div){
    		if(div.find(".loadding_msg").length > 0 || div.parent().find(".loadding_msg").length){
				div.find(".loadding_msg").remove();
    		}
    		$(div).append("<div class='loadding_msg'><img src='css/images/loading.gif'/></div>");
			$CommonPkg.error_hide(div.find(".error_main"));
    	}
    	l.success = function(data){
    		data.success = true;
    		//对数据进行分页处理
    		var url_data = l.data;
    		

			//数据过滤----   
    		
    		if(l.search && !isEmpty(l.searchMsg)){//是否需要过滤数据
    			var temp_rows = [];
    			var d;
    			for ( var i = 0; i < data.rows.length; i++) {
					d = data.rows[i];
					var sear_name = eval("d."+l.search);
					if((sear_name+"").indexOf(l.searchMsg) != -1){
						temp_rows.push(d);
					}
				}
    			data.rows = temp_rows; 
    			data.total = data.rows.length;
    			console.log(data);
    		}
    		
    		
    		if(url_data && url_data.page){
    			
    			var start = url_data.rows*(url_data.page-1);
    			var endLe = url_data.page*url_data.rows;
    			if(endLe > data.total){
    				endLe = data.total;
    			}
    			var new_rows = [];
    			for ( var i = start; i < endLe; i++) {
    				var s = data.rows[i];
    				new_rows.push(s);
    			}
    			data.result = {rows:new_rows,total:data.total};
    		} else{
    			if(data.rows){
    				data.total = data.rows.length;
    				data.result = {rows:data.rows,total:data.total};
    			} else{
    				data.result = data;
    			}
    		}
    		if(div){
    			div.find(".loadding_msg").remove();
    		}
    		success_me(data);
    	};
    	var errorMsg = l.error;
    	l.error=function(){
    		var method = l.error_method;
    		var ref_topMar = l.ref_topMar;
    		if(errorMsg){
    			errorMsg();
    		}
    		if(div && method){
    			if(div.parent().find(".loadding_msg").length > 0){
    				div.parent().parent().find(".loadding_msg").hide();
    			} else{
    				div.parent().find(".loadding_msg").hide();
    			}
    			$CommonPkg.errorRefresh(div,method,ref_topMar);
    		}
    	}
    	$.getJSON(l.url,function(data){
    		l.success(data);
		});
    }
})(jQuery)